{extend name="sitehome@style/base"/}
{block name="resources"}
<style>
	.system-page{overflow: hidden;margin-bottom: 10px;}
	.system-page li{ border:1px solid rgba(238,238,238,1);margin-right: 10px;width: 24.03%;float: left;margin-bottom: 10px;}
	.system-page li a{display: block;padding: 10px;}
	.system-page li:last-child{margin-right: 0;}
	.system-page li .img-wrap{width: 40px;height: 40px;line-height: 40px;float: left;}
	.system-page li .img-wrap img{max-width: 100%;}
	.system-page li .info-wrap{margin-left: 50px;height: 40px;}
	.system-page li .info-wrap h4{margin-bottom: 10px;}
	.system-page li .info-wrap span{color:#999;font-size: 12px;}
</style>
{/block}
{block name="main"}
{if condition="!empty($diy_view_list) || !empty($addon_name)"}
<ul class="system-page">

	{if condition="!empty($addon_name) && $addon_name != $addon_app"}
		{foreach name="$addon_diy_view_list" item="diy_view"}
			{if $diy_view['addon_info']['name'] == $addon_name}
				{notempty name="$diy_view['view_list']"}
					{foreach name="$diy_view['view_list']" item="vo"}
					<li>
						<a href="{:addon_url('diyView://sitehome/design/diyview',['name'=>strtolower($vo['name']),'addon_name'=>$diy_view['addon_info']['name']])}">
							<div class="img-wrap">
								{notempty name="$vo['icon']"}
								<img src="__ROOT__/{$vo.icon}" alt="">
								{else/}
								<img src="DIYVIEW_IMG/renovation.png"/>
								{/notempty}
							</div>
							<div class="info-wrap">
								<h4>{$vo.title}</h4>
								<span>{:time_to_date($vo['create_time'])}</span>
							</div>
						</a>
					</li>
					{/foreach}
				{/notempty}
			{/if}
		{/foreach}
	{else/}
		{foreach name="$diy_view_list" item="vo" key="k"}
		<li>
			<a {if condition="$vo['name'] == 'DIYVIEW_SITE'"} href="{:addon_url('sitehome/diy/index',['name'=>strtolower($vo['name'])])}"
			   {elseif condition="$vo['name'] == 'DIYVIEW_MEMBER'"} href="{:addon_url('sitehome/diy/memberindex',['name'=>strtolower($vo['name'])])}"
			   {else/} href="{:addon_url('diyView://sitehome/design/diyview',['name'=>strtolower($vo['name'])])}"
			{/if}>
			<div class="img-wrap">
				{notempty name="$vo['icon']"}
				<img src="__ROOT__/{$vo.icon}" alt="">
				{else/}
				<img src="DIYVIEW_IMG/renovation.png"/>
				{/notempty}
			</div>
			<div class="info-wrap">
				<h4>{$vo.title}</h4>
				<span>{:time_to_date($vo['create_time'])}</span>
			</div>
			</a>
		</li>
		{/foreach}
	{/if}
</ul>
{/if}

<div class="nc-function-search">
	<button class="layui-btn" onclick="location.href = '{:addon_url('diyview://sitehome/design/edit'.$edit_flag,['show_type'=> 'H5','addon_name' => $addon_name ])}'">新建页面</button>
</div>
<div class="nc-table-box">
	<table id="addon_list" lay-filter="addon"></table>
</div>
<script type="text/html" id="operation">
	<a class="default" lay-event="edit">编辑</a>&nbsp;
	<a class="default" lay-event="promote">推广</a>
	<a class="default" lay-event="delete">删除</a>
</script>

<script type="text/html" id="batchOperation">
	<button class="layui-btn layui-btn-primary" lay-event="delete">删除</button>
</script>
{/block}
{block name="script"}
<script>
	var table = new Table({
		elem: '#addon_list',
		filter: "addon",
		url: '{:addon_url("DiyView://sitehome/design/feature".$edit_flag)}',
		where : { addon_name : "{$addon_name}" },
		cols: [[{
			type: 'checkbox',
			unresize : 'true'
		}, {
			field: 'title',
			width: '20%',
			title: '名称',
			unresize : 'true'
		}, {
			field: 'name',
			width: '30%',
			title: '标识',
			unresize : 'true'
		}, {
			width: '20%',
			title: '创建时间',
			unresize : 'true',
			templet: function (d) {
				return nc.time_to_date(d.create_time);
			}
		}, {
			title: '操作',
			align: 'right',
			toolbar: '#operation',
			unresize : 'true'
		}]],
		bottomToolbar: "#batchOperation"
	});
	
	//监听工具条
	table.tool(function(obj) {
		var data = obj.data;
		if (obj.event === 'promote') {
			var d = {
				addon_name : data.addon_name,
				name : data.name,
				title : data.title,
				h5_url : 'diyview://wap/index/page?name=' + data.name,
				weapp_url : '/pages/diyview/diyview?name=' + data.name,
				aliapp_url : '',
				baiduapp_url : '',
				icon : ''
			};
			nc.page_promote(d);
		} else if (obj.event === 'edit') {
			location.href = nc.url("diyview://sitehome/design/edit{$edit_flag}", {
				id: data.id,
				name: data.name,
				addon_name: "{$addon_name}"
			});
		} else if (obj.event == "delete") {
			layer.confirm('确定要删除吗', function (index) {
				$.ajax({
					type: "post",
					url: '{:addon_url("DiyView://sitehome/design/deleteSiteDiyView")}',
					data: {'id': data.id},
					dataType: "JSON",
					success: function (res) {
						layer.msg(res.message);
						if (res.code == 0) {
							table.reload();
						}
					}
				});
				layer.close(index);
			});
		}
	});
	
	//批量操作
	table.bottomToolbar(function(obj) {
		
		if(obj.data.length < 1){
			layer.msg('请选择要操作的数据');
			return;
		}
		
		switch (obj.event) {
			case "delete":
				layer.confirm('确定要删除吗', function (index) {
					var id_array = new Array();
					for (i in obj.data) id_array.push(obj.data[i].id);
					$.ajax({
						type: "post",
						url: '{:addon_url("DiyView://sitehome/design/deleteSiteDiyView")}',
						data: {'id': id_array.toString()},
						dataType: "JSON",
						success: function (res) {
							layer.msg(res.message);
							if (res.code == 0) {
								table.reload();
							}
						}
					});
					layer.close(index);
				});
				break;
		}
	});
</script>
{/block}